package cn.mazexal.examapi.models.enums;

import lombok.Getter;

import java.io.Serializable;

/**
 * 客户端类型
 *
 * @author Lay
 * @date 2019/11/28
 */
@Getter
public enum ClientType implements Serializable {
    /**
     * Web端
     */
    Web(1, "Web"),

    /**
     * iOS端
     */
    iOS(2, "iOS"),

    /**
     * Android端
     */
    Android(3, "Android"),

    /**
     * H5网页
     */
    H5(4, "H5"),

    /**
     * 微信小程序
     */
    WxMiniApp(5, "WechatMiniApp"),

    /**
     * PC 端
     */
    PC(6, "PC"),

    /**
     * webApp
     * copy-zt-新增字段
     */
    WEB_APP(7, "webApp"),

    /**
     * 其他
     */
    UnKnow(99, "Others"),;

    private int value;
    private String name;

    ClientType(int value, String name) {
        this.value = value;
        this.name = name;
    }

    public static ClientType toEnum(int value) {
        for (ClientType obj : ClientType.values()) {
            if (obj.getValue() == value) {
                return obj;
            }
        }
        return ClientType.UnKnow;
    }

    public static ClientType fromTencentPlatform(String platform) {
        switch (platform.toLowerCase()) {
            case "web":
                return ClientType.Web;
            case "android":
                return ClientType.Android;
            case "ios":
                return ClientType.iOS;
            default:
                return ClientType.UnKnow;
        }
    }

    public static ClientType fromRongCloudPlatform(String platform) {
        switch (platform.toLowerCase()) {
            case "websocket":
                return ClientType.Web;
            case "android":
                return ClientType.Android;
            case "ios":
                return ClientType.iOS;
            default:
                return ClientType.UnKnow;
        }
    }
}

